<template>
	<view class="newsbox" @click="toDetail">
		<view class="pic">
			<image :src="newsObj.picurl" mode="aspectFill"></image>
		</view>
		<view class="text">
			<view class="title">{{newsObj.title}}</view>
			<view class="info" v-if="!newsObj.browsingTime?true:false">
				<text>{{newsObj.author}}</text>
				<text>{{newsObj.hits}}</text>
			</view>
			<view class="browsingTime" v-else>
				<text>最近浏览时间:   {{newsObj.browsingTime}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"Newsbox",
		props:{
			newsObj:{
				type:Object,
				default(){
					return {
						title:"组件默认标题",
						author:"张三",
						hits:668,
						picurl:"../../static/images/yingjun.jpg",

					}
				}
			}
		},
		data() {
			return {
				// 查看传过来的对象是否有browsingTime数据
				isShowBowsingTime:false,
			};
		},
		methods:{
			toDetail(){
				uni.navigateTo({
					url:`/pages/detail/detail?cid=${this.newsObj.classid}&id=${this.newsObj.id}`,
				})
				console.log('跳转到详情页面')
			}
		}
	}
</script>

<style lang="scss">
.newsbox{
	display: flex;
	.pic{
		width: 230rpx;
		height: 160rpx;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.text{
		// border: 1rpx red dashed;
		padding-left: 30rpx;
		flex:1;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		.title{
			font-size: 38rpx;
			color:#333;
			
			display: -webkit-box; /* 使用弹性盒子模型 */
			-webkit-box-orient: vertical; /* 垂直排列子元素 */
			-webkit-line-clamp: 2; /* 限制显示两行 */
			overflow: hidden; /* 隐藏超出内容 */
			text-overflow: ellipsis; /* 使用省略号 */
		}
		.info{
			font-size: 24rpx;
			color:#999;
			text{
				padding-right: 20rpx;
			}
		}
	}
}
.browsingTime{
	text{
		font-size: 24rpx;
		color:#999;
	}
}
</style>